package cn.uncode.mq.server.handlers;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.uncode.mq.network.Message;
import cn.uncode.mq.network.Topic;
import cn.uncode.mq.server.RequestHandler;
import cn.uncode.mq.util.DataUtils;

/**
 * MQ生产者处理器
 *
 * @author : juny.ye
 */
public class ProducerRequestHandler implements RequestHandler {
	
	private final static Logger LOGGER = LoggerFactory.getLogger(ProducerRequestHandler.class);
	
	public static final Map<String, Topic> maps = new HashMap<String, Topic>();

	@Override
	public Message handler(Message request) {
		List<Topic> topics = (List<Topic>) DataUtils.deserialize(request.getBody());
		if(topics != null){
			for(Topic topic:topics){
				maps.put(topic.getTopic(), topic);
			}
			LOGGER.info("Producer request handler, message:"+topics.toString());
		}else{
			LOGGER.info("Producer request handler, message is null.");
		}
		Message response = Message.newResponseMessage();
		response.setSeqId(request.getSeqId());
		return response;
	}

	

	
}
